<%@ page language="java" pageEncoding="UTF-8"%>
<%@ include file="/inc/taglibs.jsp"%>
<script type="text/javascript">
function processBack(response){
	alertMsg.correct(response.message);
	 $.pdialog.closeCurrent();
	 navTab.reload("${path }/admin/userMessageDm", "");
}
</script>
<c:choose>
	<c:when test="${model.id==0 ||empty model.id}">
		<c:set var="action" value="${path }/admin/userMessageDm/add.do"></c:set>
	</c:when>
	<c:otherwise>
		<c:set var="action" value="${path }/admin/userMessageDm/update.do"></c:set>
	</c:otherwise>
</c:choose>
<div class="pageContent">
	<form method="post" action="${action }" class="pageForm required-validate" onsubmit="return validateCallback(this, processBack);">
		<input name="id" type="hidden" size="75" value="${model.id }"/>
		<input name="contentId" type="hidden" size="75" value="${model.contentId }"/>
		<input name="senderId" type="hidden" size="75" value="${model.senderId }"/>
		<input type="hidden" name="rel" value="${rel}"/>
		<div class="pageFormContent" layoutH="57" align="left">
			<p class="nowrap">
            	<label>发送人：</label>
				<input name="sender" type="text"  value="${model.sender }"  />            
			</p>
			<c:if test="${model.id == null }">
			<p class="nowrap">
                <label>接收人类型：</label>
	            <select id="receiverType" name="receiverType" >
 					<c:forEach var="object" items="${userMessageReceiverTypeMap}">
						<option value="${object.key }">${object.value }</option>
					</c:forEach>
	            </select>
           		<script type="text/javascript">
					$("#receiverType").val("${model.receiverType}");
				</script>
            </p>
            </c:if>
            <c:if test="${model.id != null }">
            	<input name="receiverType" id="receiverType" type="hidden" size="75" value="${model.receiverType }"/>
            	<label>接收人类型：</label>${userMessageReceiverTypeMap[model.receiverType]}
            </c:if>
            <div id="receiver_div">
			<p class="nowrap">
                <label>接收人：</label>
		            <c:forEach var="userTypeMap" items="${userTypeMap}">
						<INPUT type="checkbox" name="receiver" value="${userTypeMap.key }">${userTypeMap.value }					
					</c:forEach>
					 <script type="text/javascript">
					    var receiverList = '${receiverList}';
						var strs= new Array(); //定义一数组 
						strs=receiverList.split(","); //字符分割 
				        $("input[name='receiver']").each(
				        		function(){  
				        			var _this = this;
				        			var val1 = $(_this).val();
				        		  $.each(strs, function(i,val){ 
				        			  if(val1 == val){
				        				  $(_this).attr("checked","checked") ;
				        			  }
				        		  });  
				        		}  
				        )   ;
				    </script>
            	</p>
            </div>
            
            <p class="nowrap">
				<label>发送时间：</label>
				<input type="text" name="sendTime" value="<fmt:formatDate value='${model.sendTime}' pattern='yyyy-MM-dd HH:mm:ss' />" class="date" dateFmt="yyyy-MM-dd HH:mm:ss" readonly="true">
				<a class="inputDateButton" href="javascript:;">选择</a>
			</p>
            <p class="nowrap">
				<label>过期时间：</label>
				<input type="text" name="overTime" value="<fmt:formatDate value='${model.overTime}' pattern='yyyy-MM-dd HH:mm:ss' />" class="date" dateFmt="yyyy-MM-dd HH:mm:ss" readonly="true">
				<a class="inputDateButton" href="javascript:;">选择</a>
			</p>
			<p class="nowrap">
                <label>发送类型：</label>
	            <select id="sendType" name="sendType" >
 					<c:forEach var="userMessageSendTypeMap" items="${userMessageSendTypeMap}">
						<option value="${userMessageSendTypeMap.key }">${userMessageSendTypeMap.value }</option><br/>
					</c:forEach>
	            </select>
           		<script type="text/javascript">
					$("#sendType").val("${model.sendType}");
				</script>
            </p>           
			<p class="nowrap">
                <label>平台：</label>
	            <select id="applicableId" name="applicableId" >
 					<c:forEach var="applicablePlatformMap" items="${applicablePlatformMap}">
						<option value="${applicablePlatformMap.key }">${applicablePlatformMap.value }</option>
					</c:forEach>
	            </select>
           		<script type="text/javascript">
					$("#applicableId").val("${model.applicableId}");
					$("#applicableId option[value='0']").remove();
				</script>
            </p>           
		</div>
		<div class="formBar">
			<ul>
			<li><div class="buttonActive"><div class="buttonContent"><button type="submit">保存</button></div></div></li>
				<li>
					<div class="button"><div class="buttonContent"><button type="button" class="close">返回</button></div></div>
				</li>
			</ul>
		</div>
	</form>
</div>
<script type="text/javascript">
	$("#receiverType").change(function(){
		f_receiver(this);
	});
	
	function f_receiver(obj) {
		if($(obj).val() != 3){
			$("#receiver_div").hide();
		}else{
			$("#receiver_div").show();
		}	
	}
	
	$(function(){
		var obj = $('#receiverType');
		f_receiver(obj);
	});

</script>
